/*
 * IncFile1.h
 *
 * Created: 2012-07-09 08:06:22
 *  Author: Antrykot
 */ 

#include "main.h"
#include "../sc-k/SWLcd.h"

#ifndef TRANS_H_
#define TRANS_H_

void trans();

void set_add_data();	//send aditional data (aku,vdc,pow)

void interpret();

extern u8 timeout;
extern u8 t0_cnt;

#define T0START	TCCR0B = 0 | ( 1 << CS01) 		// T0, prescale 8
#define T0STOP	TCCR0B = 0 		// T0, stopped


extern u8 t_addr;
extern u16 t_data;
extern u16 t_pom;
extern u8 t_crc;

extern u8 r_addr;
extern u16 r_data;
extern u8 r_crc;

extern u8 tr_ok;

//#define PCLK_H	 (PORTD |= (1 << 2))
//#define PCLK_L	 (PORTD &= ~(1 << 2))

#ifndef MEDIA_CO2
#define TR_P_ENABLE EIMSK |= (1 << INT0)
#else
#define TR_P_ENABLE EIMSK |= (1 << INT0)
#endif

#define TR_P_DISABLE EIMSK &= ~(1 << INT0)


#define PCK ( PIND & (1 << 2))

#ifndef MEDIA_CH4IR
#define PTX_H	(PORTD |= ( 1 << 1))
#define PTX_L	(PORTD &= ~(1 << 1))
//#define PRX		(PORTD & 1)	// bit portd.0
#else
#define PTX_H	PORTD |= ( 1 << 4)
#define PTX_L	PORTD &= ~(1 << 4)


#endif
 

extern u8 crc_data[10];
extern u8 crc_data_len;

#define STD_AKU_MINUS	1000

#define ADDR_VAKU	0x50
#define ADDR_VPOW	0x51
#define ADDR_VDC	0x52
#define ADDR_TEMP	0x53

#define P_ADDR_SYNC						0x50

#define P_ADDR_RESET_DEFAULTS			0x25
#define P_ADDR_RESET_FACT_DEFAULTS		0x26

#define P_ADDR_SW_HRANGE				0x10
#define P_ADDR_SW_HRANGEUSER			0x11
#define P_ADDR_SW_LRANGE				0x12

#define P_ADDR_CALHZ					0x61
#define P_ADDR_CALHS					0x62
#define P_ADDR_CALLZ					0x63
#define P_ADDR_CALLS					0x64

#define P_ADDR_SCALHZ					0x73
#define P_ADDR_SCALHS1					0x74
#define P_ADDR_SCALHS2					0x75
#define P_ADDR_SCALLZ					0x71
#define P_ADDR_SCALLS					0x72
#define P_ADDR_PR_ZERO					0x76

#define P_ADDR_L_RESET					0x80
#define P_ADDR_H_RESET					0x81
#define P_ADDR_IR_INIT					0x85

#define P_ADDR_L_FACTORY				0x82
#define P_ADDR_H_FACTORY				0x83

#define P_ADDR_INCAKU					0x30
#define P_ADDR_DECAKU					0x31
#define P_ADDR_INCPOW					0x32
#define P_ADDR_DECPOW					0x33
#define P_ADDR_INCAKUM					0x34
#define P_ADDR_DECAKUM					0x35
#define P_ADDR_INCPOWM					0x36
#define P_ADDR_DECPOWM					0x37

#define P_ADDR_GETREF					0xE1
#define P_ADDR_GETACT					0xE2
#define P_ADDR_GET_TCAL					0xE3
#define P_ADDR_GET_BETA					0xE4
#define P_ADDR_INCR_BETA				0xE5
#define P_ADDR_DECR_BETA				0xE6

#define P_ADDR_DCON						0x02
#define P_ADDR_DCOFF					0x03

#define P_ADDR_VERSION					0x40


#define ADD_LESS	1
#define ADD_MORE	50

#ifdef MEDIA_CO2
extern u16 debu_act;
extern u16 debu_ref;
#endif

#if defined(MEDIA_PS) || defined(MEDIA_PD)
extern u16 v_pres;
extern u16 v_rh;
#endif

#endif /* INCFILE1_H_ */